#import "DDChooseBtn.h"
@interface DDChooseBtn()
@property (nonatomic, strong) CCLabel *label;
@property (nonatomic, strong) CCLabel *contentLBL;
@property (nonatomic, strong) DDButton *IMG;
@property (nonatomic, strong) DDButton *btn;
@property (nonatomic, copy) NSString *btnTtile;
@end
@implementation DDChooseBtn
- (instancetype)initWithTitle:(NSString *)title btnTitle:(NSString *)btnTtile
{
    self = [super init];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.label.text = title;
        self.btnTtile = btnTtile;
    }
    return self;
}
- (CCLabel *)label
{
    if (!_label)
    {
        _label = [[CCLabel alloc] init];
        _label.font = FONT(UIFontWeightRegular, 15);
        _label.textColor = [UIColor lightGrayColor];
        [self addSubview:_label];
        _label.c_left.equal(self).with.coffset(GAP);
        _label.c_centerY.equal(self);
    }
    return _label;
}
- (DDButton *)btn
{
    if (!_btn)
    {
        _btn = [[DDButton alloc] init];
        _btn.backgroundColor = BLUE_COLOR;
        _btn.tag = 300;
        _btn.font = FONT(UIFontWeightRegular, 15);
        CGSize size = [self.btnTtile sizeWithFont:nil];
        _btn.layer.cornerRadius = size.height;
        [_btn addTarget:self action:@selector(yjd_actionForInsideChooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_btn];
        _btn.c_centerY.equal(self);
        _btn.c_right.equal(self).with.coffset(-GAP);
        _btn.c_size.equal(CGSizeMake(size.width * 2.2, size.height * 2.0));
    }
    return _btn;
}
- (CCLabel *)contentLBL
{
    if (!_contentLBL)
    {
        _contentLBL = [[CCLabel alloc] init];
        _contentLBL.font =FONT(UIFontWeightRegular, 15);
        _contentLBL.textColor = helpermanger().getPara().color;
        [self addSubview:_contentLBL];
        _contentLBL.c_left.equal(self.label.c_right).with.coffset(GAP);
        _contentLBL.c_centerY.equal(self);
    }
    return _contentLBL;
}
- (DDButton *)IMG
{
    if (!_IMG)
    {
        _IMG = [[DDButton alloc] init];
        _IMG.tag = 301;
        CGFloat radius = ceil(self.label.bounds.size.height);
        [_IMG addTarget:self action:@selector(yjd_actionForInsideChooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_IMG];
        _IMG.c_left.equal(self.label.c_right).with.coffset(GAP / 2.0);
        _IMG.c_centerY.equal(self);
        _IMG.c_size.equal(CGSizeMake(radius, radius));
    }
    return _IMG;
}
- (void)setBtnTtile:(NSString *)btnTtile
{
    if (_btnTtile != btnTtile)
    {
        _btnTtile = btnTtile;
        self.btn.title = _btnTtile;
    }
}
- (void)setContent:(NSString *)content
{
    if (_content != content)
    {
        _content = content;
        self.contentLBL.text = _content;
    }
}
- (void)setImageName:(NSString *)imageName
{
    if (_imageName != imageName)
    {
        _imageName = imageName;
        self.IMG.imageName = _imageName;
    }
}
- (void)yjd_actionForInsideChooseBtn:(DDButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(JTWChooseBtnWithEvent:tag:)])
    {
        [self.delegate JTWChooseBtnWithEvent:(sender.tag == 300)?JTWChooseBtnEventBtn:JTWChooseBtnEventIMG tag:self.tag];
    }
}
@end
